DEV-854: Add Nordic PPK2 instrument driver and codec test coverage - #53
Open
bhavanarallapalli wants to merge 3 commits into
Open
DEV-854: Add Nordic PPK2 instrument driver and codec test coverage#53bhavanarallapalli wants to merge 3 commits into
bhavanarallapalli wants to merge 3 commits into
Conversation
Ports the PPK2 usage of the legacy Python production test app (ASM_ProductionTest.py / ppk2_api) to the SDK for the web console's production power-consumption tests. - src/instruments/ppk2/Ppk2.ts: Web Serial transport (USB 0x1915/0xC00A, 9600 baud CDC ACM). Single continuous read loop routed by phase: metadata blob (GET_META_DATA -> ASCII until 'END'), 100 kS/s sample stream (AVERAGE_START/STOP), discard otherwise. Source/ampere meter modes, source voltage (REGULATOR_SET), DUT power toggle. Keeps no sample history; delivers calibrated microamp batches via onSamples. - src/instruments/ppk2/ppk2Codec.ts: pure codec layer - source-voltage encoding, metadata/calibration-modifier parsing (preserving the 'R value of exactly 0 is ignored' quirk), and Ppk2SampleDecoder: exact port of ppk2_api's calibration polynomial + range-transition spike filter with partial-word remainder carry (chunk-split invariant). Bounded aggregation helpers: RunningStats, MinMaxDownsampler. - Tests are fixture-driven against the original Python implementation: tests/instruments/ppk2/fixtures/generate_fixtures.py runs the installed ppk2_api offline (serial mocked) and dumps ground-truth vectors; vitest asserts numerical identity (1e-12 relative) plus chunk-split invariance and decoder reset behavior. - Version 0.1.7 -> 0.1.8. Compile/lint/test clean (182 tests). NOT yet validated against PPK2 hardware - see DEV-854 for the bench checklist. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds Nordic Power Profiler Kit II (PPK2) support to the SDK, including a pure TypeScript codec (metadata parsing, source-voltage encoding, calibrated sample decoding with spike filtering) and a Web Serial transport driver, with fixture-based tests intended to match the upstream Python ppk2_api behavior.
Changes:
- Introduces
src/instruments/ppk2/(protocol constants, codec/decoder utilities, and a Web SerialPpk2driver). - Adds Python-generated fixtures plus Vitest coverage for voltage encoding, metadata parsing, and stream decoding behavior.
- Exposes the new PPK2 APIs from
src/index.tsand bumps package version + changelog.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/instruments/ppk2/fixtures/ppk2-fixtures.json | Adds deterministic fixture vectors for voltage encoding, metadata parsing, and sample decode parity. |
| tests/instruments/ppk2/fixtures/generate_fixtures.py | Provides a one-shot Python reference fixture generator used to produce the JSON fixtures. |
| tests/instruments/ppk2/decoder.test.ts | Adds fixture-driven decoder parity tests plus RunningStats/MinMaxDownsampler coverage. |
| tests/instruments/ppk2/codec.test.ts | Adds fixture-driven tests for voltage encoding clamps and metadata parsing behavior. |
| src/instruments/ppk2/ppk2Codec.ts | Implements metadata parsing, voltage encoding, streaming sample decoding, and aggregation helpers. |
| src/instruments/ppk2/Ppk2.ts | Implements Web Serial transport driver with metadata read and sample-stream routing. |
| src/instruments/ppk2/constants.ts | Adds PPK2 USB IDs, command opcodes, and stream constants. |
| src/index.ts | Re-exports the new PPK2 driver/codec/constants from the package entrypoint. |
| package.json | Bumps package version to 0.1.8. |
| package-lock.json | Updates lockfile version fields to 0.1.8. |
| CHANGELOG.md | Documents the new PPK2 driver/codec and associated tests/fixtures. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- tests: load the JSON fixture via new URL(..., import.meta.url) instead of
__dirname so the ESM ("type": "module") test suite is self-contained and no
longer depends on Vitest's __dirname shim; drop the now-unused node:path join
import in both codec.test.ts and decoder.test.ts
- ppk2Codec.ts: annotate the clonePpk2Modifiers() range clones as Ppk2RangeTable
so the 5-tuple type is preserved explicitly rather than relying on contextual
inference
- ppk2Codec.ts: validate MinMaxDownsampler maxBins (positive integer or
Infinity), matching the existing binSize guard, and cover it with a test
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements DEV-854 SDK support for Nordic Power Profiler Kit II (PPK2), including transport, decoding, and test fixtures used by production power testing.
What changed
src/instruments/ppk2/.Notes
verisense-device-consoleDEV-854 PR that consumes these SDK capabilities.